# Copyright 2024 Google LLC
# Tools and helpers for testing Google's SAI P4 programs.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(
    default_testonly = True,
    default_visibility = ["//visibility:public"],
)

cc_library(
    name = "test_entries",
    testonly = True,
    srcs = ["test_entries.cc"],
    hdrs = ["test_entries.h"],
    deps = [
        "//gutil/gutil:overload",
        "//gutil/gutil:proto_ordering",
        "//gutil/gutil:testing",
	"//gutil/gutil:version",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//p4_pdpi:p4_runtime_session_extras",
        "//p4_pdpi:pd",
	"//p4_pdpi:ternary",
        "//p4_pdpi:translation_options",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:ipv6_address",
        "//p4_pdpi/netaddr:mac_address",
	"//p4_pdpi/packetlib:bit_widths",
        "//p4_pdpi/string_encodings:hex_string",
	"//sai_p4/instantiations/google:p4_versions",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
        "@com_github_google_glog//:glog",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_test(
    name = "test_entries_test",
    srcs = ["test_entries_test.cc"],
    deps = [
        ":test_entries",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:pd",
	"//p4_pdpi:ternary",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:ipv6_address",
        "//p4_pdpi/netaddr:mac_address",
	"//p4_pdpi/string_encodings:hex_string",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
	"@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "table_entry_generator_helper",
    testonly = True,
    srcs = ["table_entry_generator_helper.cc"],
    hdrs = ["table_entry_generator_helper.h"],
    deps = [
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:ipv6_address",
        "//p4_pdpi/netaddr:mac_address",
        "@com_github_google_glog//:glog",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/functional:bind_front",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test(
    name = "table_entry_generator_helper_test",
    srcs = ["table_entry_generator_helper_test.cc"],
    deps = [
        ":table_entry_generator_helper",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:testing",
        "//p4_pdpi:ir_cc_proto",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "table_entry_generator",
    testonly = True,
    srcs = ["table_entry_generator.cc"],
    hdrs = ["table_entry_generator.h"],
    deps = [
        ":table_entry_generator_helper",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//gutil/gutil:testing",
        "//p4_pdpi:ir_cc_proto",
        "@com_github_google_glog//:glog",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "table_entry_generator_test",
    srcs = ["table_entry_generator_test.cc"],
    shard_count = 50,
    deps = [
        ":table_entry_generator",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//p4_pdpi:entity_keys",
	"//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:pd",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "//sai_p4/instantiations/google:sai_pd_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
	"@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)
